//  Inside Microsoft Exchange 2007 Web Services 
//  Chapter 4
//
//  Copyright (c) 2007 David Sterling, Ben Spain, Mark Taylor, Huw Upshall, Michael Mainer.  
//  All rights reserved.
//
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Xml;
using System.IO;
using ProxyHelpers.EWS;

namespace DeleteFolderUsingProxy
{
    class Program
    {
        static void Main(string[] args)
        {
            ExchangeServiceBinding binding = new ExchangeServiceBinding();
            binding.Url = @"https://yourServer/ews/Exchange.asmx";
            binding.Credentials = new NetworkCredential(
                "username",
                "password",
                "domain");

            // Create a folder to delete since we can't delete distinguished folders
            //
            FolderIdType folderId = EWSHelpers.CreateFolder(
                        binding,
                        "Delete Me!",
                        new DistinguishedFolderIdType(
                            DistinguishedFolderIdNameType.inbox));

            DeleteFolderUsingProxy(binding, folderId);
        }

        /// <summary>
        /// Delete the passed folder using the proxy (from Chapter 4)
        /// </summary>
        /// <param name="binding">Binding to make calls with</param>
        /// <param name="folderIdToDelete">Id of the folder to delete</param>
        /// 
        public static void DeleteFolderUsingProxy(ExchangeServiceBinding binding, FolderIdType folderIdToDelete)
        {
            DeleteFolderType request = new DeleteFolderType();
            request.DeleteType = DisposalType.HardDelete;

            // Note that folderIdToDelete was obtained elsewhere
            //
            request.FolderIds = new BaseFolderIdType[] { folderIdToDelete };

            DeleteFolderResponseType response = binding.DeleteFolder(request);

            // We deal directly with ResponseMessageType here.  There is no dervied 
            // response message type for DeleteFolder.
            //
            ResponseMessageType responseMessage = response.ResponseMessages.Items[0];
            Console.WriteLine("Response was: " +
                       responseMessage.ResponseCode.ToString());

        }
    }
}
